package com.longcai.piaojia.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.LatestOrderEvaluateGet;
import com.longcai.piaojia.conn.LatestOrderReplyGet;
import com.longcai.piaojia.util.MyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

/**
 * Created by Administrator on 2017/1/9.
 */
public class LatestEvaluateActivity extends BaseActivity implements View.OnClickListener {

    @BoundView(R.id.latest_evaluate_et) private EditText latest_evaluate_et;
    @BoundView(R.id.latest_evaluate_count_tv) private TextView latest_evaluate_count_tv;
    private Bundle bundle;

    private LatestOrderEvaluateGet latestOrderEvaluateGet = new LatestOrderEvaluateGet(new AsyCallBack<String>() {

        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();

            try {

                MyAppointmentActivity.RefreshAppointment refreshAppointment = (MyAppointmentActivity.RefreshAppointment) getAppCallBack(MyAppointmentActivity.class);
                refreshAppointment.refresh();

                MyAppointmentDetailActivity.RefreshAppointDetail refreshAppointDetail = (MyAppointmentDetailActivity.RefreshAppointDetail) getAppCallBack(MyAppointmentDetailActivity.class);
                refreshAppointDetail.refreshDetail();

            } catch (Exception e) {
                e.printStackTrace();
            }

            finish();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_latest_evaluate);

        setBackTrue();

        setTitleName(getString(R.string.latest_evaluate_title_text));

        setRightName(getString(R.string.feedback_right_title_text), R.color.white, this);

        bundle = getIntent().getExtras();

        latest_evaluate_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                latest_evaluate_count_tv.setText(s.length() + "");

            }
        });


    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.title_right_ll:

                String content = latest_evaluate_et.getText().toString();

                if (TextUtils.isEmpty(content)) {

                    MyToast.show(context, "请输入评论内容", Toast.LENGTH_SHORT);
                    return;
                }

                latestOrderEvaluateGet.id = bundle.getString("id");
                latestOrderEvaluateGet.p_id = bundle.getString("p_id");
                latestOrderEvaluateGet.content = content;
                latestOrderEvaluateGet.user_id = BaseApplication.BasePreferences.readUserId();

                latestOrderEvaluateGet.execute(this);


                break;
        }


    }
}
